<?php
    require './config/config.php';
	require_once './user/api/config/config.php';
	if (empty($AppId) or empty($AuthAPI) or empty($API)) {
        echo "请配置config/config.php文件！";
    }
    if($_POST){
		$user=$_POST['user'];
		$password=$_POST['password'];
		if(!strlen($user) || !strlen($password)){
			echo "<script>alert('账号/密码不能为空！');location='./login.php';</script>";
		}else{
		    $sql = "select * from member where user = '$user' and state = '-1'";
            $result = mysqli_query($con,$sql);
            $rs=mysqli_fetch_array($result);
            $num = mysqli_num_rows($result);
            if($num){
                echo "<script>alert('此账号已注销且已被永久停用，请重新注册一个账号吧！');history.back();</script>";
                exit;
            }
		    $sql = "select * from member where user = '$user' and password = '" . md5($password) . "'";
            $result = mysqli_query($con,$sql);
            $rs=mysqli_fetch_array($result);
            $num = mysqli_num_rows($result);
            if($num){
                if($rs['state']=="-1"){
                    echo "<script>alert('此账号已注销且已被永久停用！');location='./login.php';</script>";
                }elseif($rs['state']=="0"){
                    echo "<script>alert('此账号已被封禁，当前无法继续使用！');location='./login.php';</script>";
                }else{
                    $_SESSION['member']=$user;
    			    $ip=getip();
    		    	$result=mysqli_query($con,"INSERT INTO `loginlog` (`id`, `user`, `ops`, `ip`, `safe`, `time`) VALUES (NULL, '".$_SESSION['member']."', '登录成功', '".$ip."', '1', '".date("Y/m/d H:i:s")."')");
    		    	if($result){
    		    	    if($_SESSION['url']==""){
    		    	        echo "<script>alert('登录成功！');location='../index.php';</script>";
    		    	    }else{
    		    	        echo "<script>alert('登录成功！');location='".$_SESSION['url']."';</script>";
    		    	    }
    		    	}else{
    		    	    $_SESSION['member']="";
    		    	    echo "<script>alert('系统异常，暂时无法为您提供服务！');location='./login.php';</script>";
    		    	}
    			    
                }
            }else{
                echo "<script>alert('密码错误！');history.back();</script>";
            }
		}
	}
?>
<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title><?php echo $ConnfigRs['name'];if($ConnfigRs['title']!=""){echo " - ".$ConnfigRs['title'];}?></title>
		 <link rel="stylesheet" href="css/head.css" />
		<link rel="stylesheet" type="text/css" href="css/login.css" />
	</head>

	<body>
<div class="dvhead">
	<div class="dvlogo"><a href="index.php">校园服务反馈系统</a></div>
</div>
		<section  class="sec">
			<form action="./login.php" method="post">
				<div class="register-box">
					<label for="username" class="username_label">
					账 号
					<input maxlength="20" name="user" type="text"
						placeholder="请输入账号" />
				</label>
				</div>
				<div class="register-box">
					<label for="username" class="username_label">
					密 码
					<input maxlength="20" type="password" name="password"
						placeholder="请输入密码" />
				</label>
				</div>
				<div class="submit_btn">
					<button type="submit" id="submit_btn">立 即 登 录</button>
				</div>
				<br />
				<div class="submit_btn">
					<a href="<?php echo $AuthAPI;?>?Id=<?php echo $AppId;?>"><button type="button" id="submit_btn">华 宇 通 行 证</button></a>
				</div>
				<br />
				<div class="submit_btn">
					<a href="./register.php"><button type="button" id="submit_btn">立 即 注 册</button></a>
				</div>
			</form>
		</section>
		<script src="js/index.js" type="text/javascript" charset="utf-8"></script>
	</body>